//
//  MyTabBarViewController.m
//  TestDemo
//
//  Created by 张润东 on 2021/8/24.
//

#import "MyTabBarViewController.h"
#import "MyCustonNavController.h"
#import "AViewController.h"
#import "BViewController.h"
#import "CViewController.h"

@interface MyTabBarViewController ()

@end

@implementation MyTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    AViewController*vc1 = [[AViewController alloc]init];
    MyCustonNavController *nav1 = [[MyCustonNavController alloc]initWithRootViewController:vc1];
    
    BViewController*vc2 = [[BViewController alloc]init];
    MyCustonNavController *nav2 = [[MyCustonNavController alloc]initWithRootViewController:vc2];
    
    CViewController*vc3 = [[CViewController alloc]init];
    MyCustonNavController *nav3 = [[MyCustonNavController alloc]initWithRootViewController:vc3];
    
    BViewController*vc4 = [[BViewController alloc]init];
    MyCustonNavController *nav4 = [[MyCustonNavController alloc]initWithRootViewController:vc4];
    
    AViewController*vc5 = [[AViewController alloc]init];
    MyCustonNavController *nav5 = [[MyCustonNavController alloc]initWithRootViewController:vc5];
  
    NSArray*vcs= @[nav1,nav2,nav3,nav4,nav5];
    self.viewControllers = vcs;
    // Do any additional setup after loading the view.
}


/// 自定义tabbar
- (void)customTabBar{
   // tabbar图标名称
   NSArray *sbNames = @[
                        @"tabbar_01",
                        @"tabbar_02",
                        @"tabbar_03",
                        @"tabbar_04",
                        @"tabbar_05"
                        ];
   //2 设置自定义tabBar
   EasyTabBar *tabBar = [EasyTabBar tabBarWithImgNames:sbNames special:YES specialIndex:3 upperFloat:22];
   //设置代理
   tabBar.delegate = self;
   // 加到系统tabbar位置
    self.tabBar.backgroundImage = [self imageWithColor:[UIColor blackColor]];
   [self.tabBar addSubview:tabBar];
   tabBar.frame = self.tabBar.bounds;
}

//点击回调
-(void)tabBarDidSelectIndex:(NSInteger)selectIndex disIndex:(NSInteger)disIndex selectBtn:(UIButton *)selBtn disBtn:(UIButton *)disBtn{
    self.selectedIndex = selectIndex;
    NSLog(@"selectIndex%ld--disIndex%ld--selBtn%ld--disBtn%ld",selectIndex,disIndex,selBtn.tag,disBtn.tag);
}

- (UIImage*)imageWithColor:(UIColor *)color{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData* imageData = UIImageJPEGRepresentation(image, 1.0f);
    image = [UIImage imageWithData:imageData];
    return image;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
